package com.hejjon.util;



import com.sun.javafx.tk.Toolkit;
import javafx.concurrent.Task;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by caoshi at 23:08 2021-09-29
 */
public class TimeTool {


    public static final SimpleDateFormat fmt = new SimpleDateFormat("HH:mm:ss.SSS");

    public interface Task {
        void excute();
    }

    /**
     * 计量时间
     * @param title
     * @param task
     */
    public static void check(String title, Task task) {
        if (task == null) return;
        title = (title == null) ? "" : ("[" + title + "]");
        System.out.println(title);
        System.out.println("开始: " + fmt.format(new Date()));
        long begin = System.currentTimeMillis();
        task.excute();
        long end = System.currentTimeMillis();
        System.out.println("结束: " + fmt.format(new Date()));

        double time = (end - begin) / 1000.0;
        System.out.println("耗时: " + time + "秒");
        System.out.println("----------------------------------------");
    }




}
